package com.imoblife.brainwavestus.customview;


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.imoblife.brainwavestus.R;
import com.imoblife.brainwavestus.util.DebugServerPushDataUtil;
import com.imoblife.brainwavestus.util.DebugUtil;


import android.app.Activity;

public class NewProductsView extends FreatureProductsView {

	public NewProductsView(Activity activity) {
		super(activity);
		
	}

	protected void initalizeProductsNode() {

		mAbsProductList.setProductLayout(R.layout.tb_new_product_node);
		
	}

	
	protected List<String> getProductsData() throws IOException, JSONException {

		InputStream inputStream = null;
		if(DebugServerPushDataUtil.isOpenProductJsonDebug){
			try {
				inputStream = mActivity.openFileInput("products.json");
			} catch (Exception e) {
			}
		}
		if (inputStream == null) {
			inputStream = mActivity.getAssets().open("products.json");
		} else {
			DebugUtil.debug(TAG, "��ȡ�����̵��ļ��ɹ�");
		}

		byte[] data = new byte[inputStream.available()];

		inputStream.read(data);
		inputStream.close();
		String string = new String(data);

		DebugUtil.debug(TAG, string);

		JSONObject jsonObject = new JSONObject(string);

		JSONArray jsonArray = jsonObject.getJSONArray("New");

		String[] products = new String[jsonArray.length()];

		for (int i = 0; i < products.length; i++) {

			mProductsDate.add(jsonArray.getJSONObject(i)
					.getString("productId"));

			DebugUtil.debug(TAG, products[i]);
		}
		return mProductsDate;

	}

}
